home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 4
/
MacMania 4.toast
/
/
Demo's
/
Igor Demo Pro
/
1 PutContentsIn Igor Pro Folder
/
WaveMetrics Procedures
/
Math Functions
/
Complex Math Functions
< prev
next >
Wrap
Text File
|
1994-02-18
|
2KB
|
104 lines
Function/D cabs(z)
Variable/D/C z
Variable/D temp,rz,iz
rz= abs(real(z))
iz= abs(imag(z))
if(iz > rz)
temp = rz
rz = iz
iz = temp
endif
if((rz+iz) == rz)
return rz | underflow
endif
return rz*sqrt(1.0 + (iz/rz)^2)
End
Function/C/D csqrt( z)
Variable/C/D z
Variable/C/D r
Variable/D mag, t,tt
mag = cabs(z)
if( mag == 0 )
r = 0
else
if(real(z) > 0)
t = sqrt(0.5 * (mag + real(z)) )
r= cmplx(t,0.5 * imag(z) / t)
else
t = sqrt(0.5 * (mag - real(z)) )
if(imag(z) < 0)
t = -t
endif
r= cmplx(0.5 * imag(z) / t,t)
endif
endif
return r
End
Function/C/D cexp(z)
Variable/C/D z
Variable/D expx = exp(real(z));
Return cmplx( expx * cos(imag(z)), expx * sin(imag(z)))
end
Function/C/D cln(z)
Variable/C/D z
Return cmplx( ln(cabs(z)), atan2(imag(z),real(z)))
end
Function/C/D csin(z)
Variable/C/D z
Return cmplx(sin(real(z)) * cosh(imag(z)), cos(real(z)) * sinh(imag(z)))
end
Function/C/D ccos(z)
Variable/C/D z
Return cmplx(cos(real(z)) * cosh(imag(z)), -sin(real(z)) * sinh(imag(z)))
end
Function/D/C cpowi(a, n) | returns a^n where a is complex and n is an integer
Variable/D/C a
Variable/D n
Variable/D/C p=cmplx(1,0) | the result
if( trunc(n)!=n ) | is n really a real integer?
return cmplx(nan,nan) | no- can't do it
endif
if(n == 0)
return p
endif
if(n < 0)
n = -n;
a=1/ a
endif
do
if(n %& 1)
p= p*a
endif
n /= 2
if(n != 0)
a *= a
else
break;
endif
while(1)
return p
End